# -*- coding: UTF-8 -*-
#-------------------------------------------------------------------------------
# Name:        interfaces.py
# Purpose:
#
# Author:      Drago@
#
# Created:     06.08.2009
# Copyright:   (c) Drago@ 2009
# Licence:     <your licence>
#-------------------------------------------------------------------------------
#!/usr/bin/env python

class IBaseService(object):
    """
        Base interface for Pygs service
    """

    def setServiceProvider(self, serviceProvider):
        pass

    def getServiceProvider(self):
        pass

    def startup(self, params = None):
        pass

    def shutdown(self):
        pass

    def restart(self, params = None):
        pass

class ISecurityInterface(IBaseService):
    """
        Security interface
    """

    def __init__(self):
        pass

    def login(self, params):
        raise NotImplementedError()

    def logout(self, token):
        raise NotImplementedError()

    def hasRigths(self, token, operation):
        raise NotImplementedError()

class IInServiceInterface(IBaseService):
    """
        "In service" interface
    """

    def __init__(self):
        pass

    def savePoints(self, token, trackingObject, points):
        raise NotImplementedError()

class IOutServiceInterface(IBaseService):
    """
        "Out service" interface
    """

    def __init__(self):
        pass

    def getTrek(self, token, trekingObjectId, dateFrom, dateTo):
        raise NotImplementedError()

class IPersistenceInterface(IBaseService):
    """
       Persistence interface
    """

    def __init__(self):
        pass

    def addPoints(self, points):
        raise NotImplementedError()

    def getToken(self, userName, passwd, expirationDate):
        raise NotImplementedError()

    def deleteToken(self, token):
        raise NotImplementedError()
    
    def hasRight(self, token, rightType):
        raise NotImplementedError()

    def isSessionExpierd(self, token):
        raise NotImplementedError()
    
class ISecurityPersistence(IBaseService):
    pass

class IAuthentication(IBaseService):
    pass


        
class ImplementationConfig(object):
    """
        Represents config for service implementation
    """
    module = None
    className = None
    remote = None
    remoteAddress = None
    params = None

    def __init__(self, **kwargs):
        self.module = kwargs["module"]
        self.className = kwargs["className"]
        self.remote = kwargs["remote"]
        self.remoteAddress = kwargs["remoteAddress"]
        self.params = kwargs["params"]
        
    def isEqual(self, config):
        if self.remote <> config.remote:
            return False
        if self.remote:
            return self.remoteAddress == config.remoteAddress
        else:
            return self.module == config.module and self.className == config.className and self.params == config.params 
